package cashpointer.mobile.support;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import cashpointer.mobile.R;

/**
 * Klasa wspierajaca administrowanie powiadomieniami.
 * @author wojtek
 *
 */
public class NotificationSupportManager {	
	// Identyfikatory powiadomien
    public static final int UPDATE_NOTIFY = 1;
    
	/**
	 * Funkcja wyswietlajaca komunikat na ekranie.
	 * @param context
	 * @param text
	 */
	static public void showToastNotification(Context context, String text) {
		if (text != null && context != null) {
			int duration = Toast.LENGTH_SHORT;
			Toast toast = Toast.makeText(context, text, duration);
			toast.show();
		}
	}
	
	/**
	 * Funkcja budujaca komunikat ostrzezenia.
	 * @param activity
	 * @param info
	 * @return
	 */
    static public Dialog buildAlertDialog(Activity activity, String info) {
    	LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
		View layout = inflater.inflate(R.layout.window_dialog, (ViewGroup) activity.findViewById(R.id.alertDialog));

		TextView text = (TextView) layout.findViewById(R.id.alertDialogTextView);
		text.setText(info);
		ImageView image = (ImageView) layout.findViewById(R.id.alertDialogImageView);
		image.setImageResource(R.drawable.alert_icon);

		AlertDialog.Builder builder = new AlertDialog.Builder(activity);
		builder.setView(layout);
		builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
           }
    	});
		
		return builder.create(); 
    }
    
	
	/**
	 * Funkcja budujaca komunikat ostrzezenia.
	 * @param activity
	 * @param info
	 * @return
	 */
    static public Dialog buildInfoDialog(Activity activity, String info) {
    	LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
		View layout = inflater.inflate(R.layout.window_dialog, (ViewGroup) activity.findViewById(R.id.alertDialog));

		TextView text = (TextView) layout.findViewById(R.id.alertDialogTextView);
		text.setText(info);
		ImageView image = (ImageView) layout.findViewById(R.id.alertDialogImageView);
		image.setImageResource(R.drawable.info_icon);

		AlertDialog.Builder builder = new AlertDialog.Builder(activity);
		builder.setView(layout);
		builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
           }
    	});
		
		return builder.create(); 
    }
}
